<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>AP3-SP-les phoques du desert</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="verification.js"></script>
</head>
<body onMouseMove="display_c()">

	<?php
	include_once("connect.php");

	error_reporting(E_ALL | E_STRICT);
	ini_set('display_errors', true);

	$pseudo = "";
	$password = "";
	$verif_password = "";
	$mail = "";
	$verif_mail = "";
	$nom= "";
	$prenom = "";
	$adresse = "";
	$tel = "";
	$displayForm = true;
	$message1 = "";
	$message2 = "";
	$message3 = "";
	$message4 = "";
	$message5 = "";
	$message6 = "";
	$message7 = "";
	$message8 = "";
	$message9 = "";
	$message10 = "";
	$message11 = "";
	$message12 = "";
	$message = $message1 + $message2+ $message3+ $message4 +$message5+$message6+$message7+$message8+$message9+$message10+$message11+$message12;
	
	if (isset($_POST["valider"])) {
		if (isset($_POST["pseudo"]))
		$pseudo = $_POST["pseudo"];
		
		if (isset($_POST["password"])) 
		$password = $_POST["password"];
		
		if (isset($_POST["verif_password"]))
		$verif_password = $_POST["verif_password"];
		
		if (isset($_POST["mail"])) 
		$mail = $_POST["mail"];
		
		if (isset($_POST["verif_mail"])) 
		$verif_mail = $_POST["verif_mail"];
		
		if (isset($_POST["nom"])) 
		$nom = $_POST["nom"];
		
		if (isset($_POST["prenom"])) 
		$prenom = $_POST["prenom"];
		
		if (isset($_POST["adresse"])) 
		$adresse = $_POST["adresse"];

		if (isset($_POST["tel"]))
		$tel = $_POST["tel"];
		
		$displayForm = false;
			
			//alerte message vide
		if ($pseudo == "") { 
			$displayForm = true; 
			$message1 .= "Le pseudo ne peut être vide";
		}
				
		if ($password == "") { 
			$displayForm = true; 
			$message2 .= "Le password ne peut être vide";
		}

		if ($verif_password == "") { 
			$displayForm = true; 
			$message3 .= "La verification du password ne peut être vide";
		}
				
		if ($mail == "") { 
			$displayForm = true; 
			$message4 .= "Le mail ne peut être vide";
		}
			
		if ($verif_mail == "") {
			$displayForm = true;
			$message5 .= "La verification du mail ne peut être vide";
		}
			
		if ($nom == "") { 
			$displayForm = true; 
			$message6 .= "Le nom ne peut être vide";
		}
				
		if ($prenom == "") { 
			$displayForm = true; 
			$message7 .= "Le prenom ne peut être vide";
		}
			
		if (!preg_match("/^(.+)@(.+)\.(.+)$/",$mail)) {
			$displayForm = true;
			$message8 .= "L'adresse doit etre au format exemple@exemple.com";
		}
			
		if ($mail != $verif_mail) {
			$displayForm = true;
			$message9 .= "Les adresses e-mail doivent correspondre";
		}
			
		if ($password != $verif_password) {
			$displayForm = true;
			$message10 .= "Les passwords doivent correspondre";
		}
			
		if(isset($_POST["tel"]))	{
			if (!preg_match("/^[0-9]{10}$/",$tel) && ($tel!="") ) {
				$displayForm = true;
				$message11 .= "Le numéro de téléphone doit avoir la forme XXXXXXXXXX";
			}	
		}	
			
		$query=mysql_query("select pseudo from AP3_SP_user");
	
		while($row=mysql_fetch_assoc($query))	{
			if($row["pseudo"] == $pseudo){
				$displayForm = true;
				$message12 .="Le pseudo existe déjà";
			}
		}

		if ($message != "")
			echo "<div id='message'>" .$message ."</div>";
	}

	if ($displayForm) { 
	?>
		<div id="all">
		
			<div id="header">		
			<h1> Inscription !</h1>
			<a href="index.php"> Retour vers l'Index </a>
			</div>
			
			<div id="content">
				<div id="formulaire_inscription">
					<form name="formulaire_inscription" method="post" action="inscription.php">
						<table>
							<tr>
								<th colspan="2">Coordonées du Compte :</th> 
								<th colspan="2">Coordonées Personnelles :</th>
							</tr>
						<tr>
							<td class="ig">Votre Pseudo* :</td>
							<td class="ig">
								<input  type="text"  name="pseudo" value="<?php echo $pseudo;?>" size="30"  onFocus="init(this)" onKeyUp="verif(this)"  onBlur="verif(this)"/>
								<?php if(isset($_POST["pseudo"])) echo '<br/><span class="msg">'.$message1.'</span>'; ?>
							</td>
							<td class="real">Votre Nom*:	</td>
							<td class="real">
							<input   type="text" name="nom" value="<?php echo $nom;?>" size="30"  onFocus="init(this)" onKeyUp="verif(this)"  onBlur="verif(this)"/>
							<?php if(isset($_POST["nom"])) echo '<br/><span class="msg">'.$message6.'</span>'; ?>
							</td>
						</tr>
						
						<tr>
						<td class="ig">Votre Mot de passe* :</td>
							<td class="ig">
								<input  type="password" name="password" value="<?php echo $password;?>" size="30"	onFocus="init(this)"  onKeyUp="password1(this)"  onBlur="password2(this)"/>
							<?php if(isset($_POST["password"])) echo '<br/><span class="msg">'.$message2.'</span>'; ?>
							</td>
							<td class="real">Votre Prenom*:</td>
							<td class="real">
							<input  type="text" name="prenom" value="<?php echo $prenom;?>"  size="30"	onFocus="init(this)" onKeyUp="verif(this)"  onBlur="verif(this)"/>
							<?php if(isset($_POST["prenom"])) echo '<br/><span class="msg">'.$message7.'</span>'; ?>
							</td>					
						</tr>
						
						<tr>
						<td class="ig">Vérification Mot de passe* :</td>
							<td class="ig">
							<input  type="password" name="verif_password" value="<?php echo $verif_password;?>" size="30" 	onFocus="init(this)" onKeyUp="verif_password1(this)"  onBlur="verif_password2(this)"/>
							<?php if(isset($_POST["verif_password"]))  echo '<br/><span class="msg">'.$message10.'</span>'; ?>
							</td>
							<td colspan="2" rowspan="2" class="real">Votre Adresse: <br/> 
							<input type="text" name="adresse"  value="<?php echo $adresse;?>" size="40"	 onFocus="init(this)" onKeyUp="verif(this)"  onBlur="verif(this)"/><br/><br/></td>	
						</tr>
						
						<tr>
						<td class="ig">Votre Adresse email* :</td>
							<td class="ig">
							<input   type="text" name="mail" value="<?php echo $mail;?>" size="30" 	onFocus="init(this)" onKeyUp="mail1(this)"  onBlur="mail2(this)"/>
							<?php if(isset($_POST["mail"])) echo  '<br/><span class="msg">'.$message8.'</span>'; ?>
							</td>
							
						</tr>
						
						<tr>
						<td>Véfication Adresse email*:</td>
							<td>
							<input  class="ig" type="text" name="verif_mail" value="<?php echo $verif_mail;?>" size="30"onFocus="init(this)" onKeyUp="verif_mail1(this)"  onBlur="verif_mail2(this)"/>
							<?php if(isset($_POST["verif_mail"])) echo '<br/><span class="msg">'.$message9.'</span>'; ?>
							</td>
							<td>Votre Numéro de telephone:</td>
							<td>
							<input  class="real" type="text" name="tel" value="<?php echo $tel;?>" size="15"  onFocus="init(this)" onKeyUp="tel1(this)" onBlur="tel2(this)"/>
							<?php if(isset($_POST["tel"])) echo '<br/><span class="msg">'.$message11.'</span>'; ?>
							</td>					
						</tr>
						</table>
						<input class="valid" type="submit" name="valider" value="S'incrire !" onSubmit="return veriftotal()" />					
					
					</form>
					</div>
					<?php 
	} 
	else {
		if($password!="" && $pseudo!="" && $nom!="" && $prenom!="" && $mail!="" && $password == $verif_password && $mail == $verif_mail){
			$password =md5($password);
			$requete="
				insert into AP3_SP_user(password,pseudo,nom,prenom,adresse,tel,mail,id_type,id_image,nb_post)
				values ('".$password."','".$pseudo."','".$nom."','".$prenom."','".$adresse."','".$tel."','".$mail."','2','0','0');";

			$result=mysql_query($requete) ;
			if ($result == FALSE)
				echo 'erreur insert';
			else{
				echo '<span class="valider">';
				echo $prenom ." "  .$nom . " , tes données ont été bien entrées...<br/>";
				echo "<a href='index.php'>retour à l'accueil</a>";
				echo '</span>';
			}
		}
		else{
			echo "<a href = index.php />retourner à l'ecran de connexion</a><br/>";
			echo " les champs sont vides";
		}		
	}?>
					
			</div>		
			<div id="footer">
				<div id="ct">
				</div>
		
				<div id="droit">
				<marquee>Made by Les Phoques Du Désert</marquee>
				</div>
			</div>
		</div>
</body>